<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" >
  <xsl:output method="html" encoding="UTF-16"/>

  <xsl:template name="replace_and_keep">
    <xsl:param name="string"/>
    <xsl:param name="from"/>
    <xsl:param name="to"/>
    <xsl:choose>
      <xsl:when test="contains($string, $from)">
        <xsl:value-of select="substring-before($string, $from)" />
        <xsl:copy-of select="$to" />
        <xsl:call-template name="replace_and_keep">
          <xsl:with-param name="string" select="substring-after($string, $from)" />
          <xsl:with-param name="from" select="$from"/>
          <xsl:with-param name="to" select="$to" />
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$string" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="replace">
    <xsl:param name="string"/>
    <xsl:param name="from"/>
    <xsl:param name="to"/>
    <xsl:choose>
      <xsl:when test="contains($string, concat('_', $from))">
      </xsl:when>
      <xsl:when test="contains($string, concat($from, ','))">
        <xsl:copy-of select="concat($to, ',')" />
      </xsl:when>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="replace_mod">
    <xsl:param name="string"/>
    <xsl:param name="from"/>
    <xsl:param name="to"/>
    <xsl:choose>
      <xsl:when test="contains($string, concat('_', $from))">
      </xsl:when>
      <xsl:when test="contains($string, concat($from, ','))">
      </xsl:when>
      <xsl:when test="contains($string, $from)">
        <xsl:copy-of select="$to" />
      </xsl:when>
    </xsl:choose>
  </xsl:template>


  <xsl:template match="/">

    <xsl:variable name="Dictionary" select="//dictionary" />
    <xsl:variable name="Type" select="//full_name" />

    <div class="UnitDetails">
      <div>
        <h2><xsl:value-of select="//description/name"/></h2>
        <table class="WeaponTable">
            <tr>
              <td rowspan="9"><img class="InfoImg" src="pics/Info/{$Dictionary}_INFO.jpg" alt="Not Available"  title="" /></td>
              <th />
              <th colspan="2">Weapons</th>
              <th><div class="SpacerCell" /></th>
              <th />
              <th>Defence</th>
              <th><div class="SpacerCell" /></th>
              <th />
              <th>Mental</th>
            </tr>
            <tr>
              <th />
              <th>Primary</th>
              <th>Secondary</th>
              <th />
              <td class="LabelCell" onmouseover="showTooltip(event, 'armour');">Armour:</td>
              <td><xsl:value-of select="//stat_pri_armour/armour" /></td>
              <td />
              <td class="LabelCell" onmouseover="showTooltip(event, 'morale');">Morale:</td>
              <td><xsl:value-of select="//stat_mental/morale" /></td>
            </tr>
            <tr>
              <td class="LabelCell">Type:</td>
              <td><xsl:value-of select="//stat_pri/sound" /></td>
              <td><xsl:value-of select="//stat_sec/sound" /></td>
              <td />
              <td class="LabelCell" onmouseover="showTooltip(event, 'shield');">Shield:</td>
              <td><xsl:value-of select="//stat_pri_armour/shield" /></td>
              <td />
              <td class="LabelCell" onmouseover="showTooltip(event, 'discipline');">Discipline:</td>
              <td><xsl:value-of select="//stat_mental/discipline" /></td>
            </tr>
            <tr>
              <td class="LabelCell" onmouseover="showTooltip(event, 'attack');">Attack:</td>
              <td><xsl:value-of select="//stat_pri/attack" /></td>
              <td><xsl:value-of select="//stat_sec/attack" /></td>
              <td />
              <td class="LabelCell" onmouseover="showTooltip(event, 'skill');">Skill:</td>
              <td><xsl:value-of select="//stat_pri_armour/def_skill" /></td>
              <td />
              <td class="LabelCell" onmouseover="showTooltip(event, 'training');">Training:</td>
              <td><xsl:value-of select="//stat_mental/training" /></td>
            </tr>
            <tr>
              <td class="LabelCell" onmouseover="showTooltip(event, 'charge');">Charge:</td>
              <td><xsl:value-of select="//stat_pri/charge" /></td>
              <td><xsl:value-of select="//stat_sec/charge" /></td>
              <td class="SpacerCell"/>
              <th />
              <th>Recruitment</th>
              <th class="SpacerCell" />
              <th />
              <th>Other</th>
            </tr>
            <tr>
              <td class="LabelCell" onmouseover="showTooltip(event, 'lethality');">Lethality:</td>
              <td><xsl:value-of select="//stat_pri/lethality" /></td>
              <td><xsl:value-of select="//stat_sec/lethality" /></td>
              <td />
              <td class="LabelCell" onmouseover="showTooltip(event, 'soldiers');">Soldiers:</td>
              <td><xsl:value-of select="//soldier/soldiers" /></td>
              <td />
              <td class="LabelCell" onmouseover="showTooltip(event, 'hitpoints');">Hit Points:</td>
              <td><xsl:value-of select="//stat_health/hit_points" /></td>
            </tr>
            <tr>
              <td class="LabelCell" onmouseover="showTooltip(event, 'range');">Range:</td>
              <td><xsl:value-of select="//stat_pri/range" /></td>
              <td><xsl:value-of select="//stat_sec/range" /></td>
              <td />
              <td class="LabelCell" onmouseover="showTooltip(event, 'cost');">Cost:</td>
              <td><xsl:value-of select="//stat_cost/cost" /></td>
              <td />
              <td class="LabelCell" onmouseover="showTooltip(event, 'mass');">Mass:</td>
              <td><xsl:value-of select="//soldier/mass" /></td>
            </tr>
            <tr>
              <td class="LabelCell" onmouseover="showTooltip(event, 'ammo');">Ammo:</td>
              <td><xsl:value-of select="//stat_pri/ammo" /></td>
              <td><xsl:value-of select="//stat_sec/ammo" /></td>
              <td />
              <td class="LabelCell" onmouseover="showTooltip(event, 'upkeep');">Upkeep:</td>
              <td><xsl:value-of select="//stat_cost/upkeep" /></td>
              <td class="SpacerCell"/>
              <td />
              <td />
            </tr>
            <tr>
              <td />
              <td />
              <td />
              <td />
              <td class="LabelCell" onmouseover="showTooltip(event, 'turns');">Turns:</td>
              <td><xsl:value-of select="//stat_cost/turns" /></td>
              <td />
              <td />
              <td />
            </tr>
        </table>

        <div class="Attributes">
          <!-- Show conditionaly weapon attributes -->
          <xsl:if test="unit[stat_pri_attr!='no']" >
            <div><span class="LabelCell">Primary Weapon Attributes: </span>

          <xsl:variable name="attributes" select="//stat_pri_attr" />
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'area'" />
            <xsl:with-param name="to"> Area attack</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'ap'" />
            <xsl:with-param name="to"> Armour Piercing</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'bp'" />
            <xsl:with-param name="to"> Body Piercing</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'light_spear'" />
            <xsl:with-param name="to"> Light spear</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'long_pike'" />
            <xsl:with-param name="to"> Long pike phalanx</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'short_pike'" />
            <xsl:with-param name="to"> Short pike phalanx</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'spear'" />
            <xsl:with-param name="to"> Spear</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'prec'" />
            <xsl:with-param name="to"> Thrown before charge</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'thrown'" />
            <xsl:with-param name="to"> Thrown missile</xsl:with-param>
          </xsl:call-template>

          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'area'" />
            <xsl:with-param name="to"> Area attack</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'ap'" />
            <xsl:with-param name="to"> Armour Piercing</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'bp'" />
            <xsl:with-param name="to"> Body Piercing</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'light_spear'" />
            <xsl:with-param name="to"> Light spear</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'long_pike'" />
            <xsl:with-param name="to"> Long pike phalanx</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'short_pike'" />
            <xsl:with-param name="to"> Short pike phalanx</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'spear'" />
            <xsl:with-param name="to"> Spear</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'prec'" />
            <xsl:with-param name="to"> Thrown before charge</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'thrown'" />
            <xsl:with-param name="to"> Thrown missile</xsl:with-param>
          </xsl:call-template>


          </div>
          </xsl:if>
          <xsl:if test="unit[stat_sec_attr!='no']" >
            <div><span class="LabelCell">Secondary Weapon Attributes: </span>

          <xsl:variable name="attributes" select="//stat_sec_attr" />
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'area'" />
            <xsl:with-param name="to"> Area attack</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'ap'" />
            <xsl:with-param name="to"> Armour Piercing</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'bp'" />
            <xsl:with-param name="to"> Body Piercing</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'light_spear'" />
            <xsl:with-param name="to"> Light spear</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'long_pike'" />
            <xsl:with-param name="to"> Long pike phalanx</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'short_pike'" />
            <xsl:with-param name="to"> Short pike phalanx</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'spear'" />
            <xsl:with-param name="to"> Spear</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'prec'" />
            <xsl:with-param name="to"> Thrown before charge</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'thrown'" />
            <xsl:with-param name="to"> Thrown missile</xsl:with-param>
          </xsl:call-template>

          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'area'" />
            <xsl:with-param name="to"> Area attack</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'ap'" />
            <xsl:with-param name="to"> Armour Piercing</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'bp'" />
            <xsl:with-param name="to"> Body Piercing</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'light_spear'" />
            <xsl:with-param name="to"> Light spear</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'long_pike'" />
            <xsl:with-param name="to"> Long pike phalanx</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'short_pike'" />
            <xsl:with-param name="to"> Short pike phalanx</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'spear'" />
            <xsl:with-param name="to"> Spear</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'prec'" />
            <xsl:with-param name="to"> Thrown before charge</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'thrown'" />
            <xsl:with-param name="to"> Thrown missile</xsl:with-param>
          </xsl:call-template>

          </div>
          </xsl:if>
          <div><span class="LabelCell">Attributes: </span>

          <xsl:variable name="attributes" select="//attributes" />
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'sea_faring'" />
            <xsl:with-param name="to"> Can board ships</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'can_sap'" />
            <xsl:with-param name="to"> Can dig tunnels</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'cantabrian_circle'" />
            <xsl:with-param name="to"> Can form cantabrian circle</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'hide_anywhere'" />
            <xsl:with-param name="to"> Can hide anywhere</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'hide_forest'" />
            <xsl:with-param name="to"> Can hide in forest</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'hide_long_grass'" />
            <xsl:with-param name="to"> Can hide in long grass</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'can_run_amok'" />
            <xsl:with-param name="to"> Can run amok</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'no_custom'" />
            <xsl:with-param name="to"> Can't be used in custom battle</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'frighten_mounted'" />
            <xsl:with-param name="to"> Frightens cavalry</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'frighten_foot'" />
            <xsl:with-param name="to"> Frightens infantry</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'general_unit'" />
            <xsl:with-param name="to"> General bodyguards</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'command'" />
            <xsl:with-param name="to"> Give bonus to nearby troop</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'hardy'" />
            <xsl:with-param name="to"> Hardy</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'hide_improved_forest'" />
            <xsl:with-param name="to"> Improved hiding in forest</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'mercenary_unit'" />
            <xsl:with-param name="to"> Mercenary</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'general_unit_upgrade'" />
            <xsl:with-param name="to"> Reformed general bodyguards</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'very_hardy'" />
            <xsl:with-param name="to"> Very Hardy</xsl:with-param>
          </xsl:call-template>

          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'sea_faring'" />
            <xsl:with-param name="to"> Can board ships</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'can_sap'" />
            <xsl:with-param name="to"> Can dig tunnels</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'cantabrian_circle'" />
            <xsl:with-param name="to"> Can form cantabrian circle</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'hide_anywhere'" />
            <xsl:with-param name="to"> Can hide anywhere</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'hide_forest'" />
            <xsl:with-param name="to"> Can hide in forest</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'hide_long_grass'" />
            <xsl:with-param name="to"> Can hide in long grass</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'can_run_amok'" />
            <xsl:with-param name="to"> Can run amok</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'no_custom'" />
            <xsl:with-param name="to"> Can't be used in custom battle</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'frighten_mounted'" />
            <xsl:with-param name="to"> Frightens cavalry</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'frighten_foot'" />
            <xsl:with-param name="to"> Frightens infantry</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'general_unit'" />
            <xsl:with-param name="to"> General bodyguards</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'command'" />
            <xsl:with-param name="to"> Give bonus to nearby troop</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'hardy'" />
            <xsl:with-param name="to"> Hardy</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'hide_improved_forest'" />
            <xsl:with-param name="to"> Improved hiding in forest</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'mercenary_unit'" />
            <xsl:with-param name="to"> Mercenary</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'general_unit_upgrade'" />
            <xsl:with-param name="to"> Reformed general bodyguards</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$attributes" />
            <xsl:with-param name="from" select="'very_hardy'" />
            <xsl:with-param name="to"> Very Hardy</xsl:with-param>
          </xsl:call-template>

          </div>
          <div><span class="LabelCell">Formation: </span>

          <xsl:variable name="formations" select="//formation/formations" />
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$formations" />
            <xsl:with-param name="from" select="'horde'" />
            <xsl:with-param name="to"> Horde</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$formations" />
            <xsl:with-param name="from" select="'phalanx'" />
            <xsl:with-param name="to"> Phalanx</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$formations" />
            <xsl:with-param name="from" select="'square'" />
            <xsl:with-param name="to"> Square</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$formations" />
            <xsl:with-param name="from" select="'testudo'" />
            <xsl:with-param name="to"> Testudo</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$formations" />
            <xsl:with-param name="from" select="' wedge'" />
            <xsl:with-param name="to"> Wedge</xsl:with-param>
          </xsl:call-template>

          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$formations" />
            <xsl:with-param name="from" select="'horde'" />
            <xsl:with-param name="to"> Horde</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$formations" />
            <xsl:with-param name="from" select="'phalanx'" />
            <xsl:with-param name="to"> Phalanx</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$formations" />
            <xsl:with-param name="from" select="'square'" />
            <xsl:with-param name="to"> Square</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$formations" />
            <xsl:with-param name="from" select="'testudo'" />
            <xsl:with-param name="to"> Testudo</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$formations" />
            <xsl:with-param name="from" select="' wedge'" />
            <xsl:with-param name="to"> Wedge</xsl:with-param>
          </xsl:call-template>

            <span class="LabelCell" onmouseover="showTooltip(event, 'spacing');"> Side/Back spacing: </span>
            <xsl:value-of select="//formation/side_spacing"/> /
            <xsl:value-of select="//formation/front_spacing"/>
          </div>
          <xsl:if test="count(//mount_effect)">
            <div><span class="LabelCell">Mount effects: </span> <xsl:value-of select="//mount_effect" /></div>
          </xsl:if>
          <div><span class="LabelCell">Ownership: </span>

          <xsl:variable name="ownership" select="//ownership" />
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'gauls'" />
            <xsl:with-param name="to"> Aedui</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'romans_julii'" />
            <xsl:with-param name="to"> Arche Seleukeia</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'scythia'" />
            <xsl:with-param name="to"> Arverni</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'saba'" />
            <xsl:with-param name="to"> As'Sab'yn wal'Jau</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'romans_brutii'" />
            <xsl:with-param name="to"> Baktria</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'britons'" />
            <xsl:with-param name="to"> Casse</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'thrace'" />
            <xsl:with-param name="to"> Epeiros</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'dacia'" />
            <xsl:with-param name="to"> Getai</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'romans_scipii'" />
            <xsl:with-param name="to"> Hayasdan</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'spain'" />
            <xsl:with-param name="to"> Iberia</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'greek_cities'" />
            <xsl:with-param name="to"> Koinon Hellenon</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'macedon'" />
            <xsl:with-param name="to"> Makedonia</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'parthia'" />
            <xsl:with-param name="to"> Pahlav</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'carthage'" />
            <xsl:with-param name="to"> Pontos</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'numidia'" />
            <xsl:with-param name="to"> Ptolemaioi</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'egypt'" />
            <xsl:with-param name="to"> Safot Softim biKarthadast</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'pontus'" />
            <xsl:with-param name="to"> Saka</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'armenia'" />
            <xsl:with-param name="to"> Sauromatae</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'seleucid'" />
            <xsl:with-param name="to"> Senatvs Popvlvsqve Romanvs</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'germans'" />
            <xsl:with-param name="to"> Swēbōzez</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'merc'" />
            <xsl:with-param name="to"> Mercenary</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'slave'" />
            <xsl:with-param name="to"> Eleutheroi</xsl:with-param>
          </xsl:call-template>

          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'gauls'" />
            <xsl:with-param name="to"> Aedui</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'romans_julii'" />
            <xsl:with-param name="to"> Arche Seleukeia</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'scythia'" />
            <xsl:with-param name="to"> Arverni</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'saba'" />
            <xsl:with-param name="to"> As'Sab'yn wal'Jau</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'romans_brutii'" />
            <xsl:with-param name="to"> Baktria</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'britons'" />
            <xsl:with-param name="to"> Casse</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'thrace'" />
            <xsl:with-param name="to"> Epeiros</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'dacia'" />
            <xsl:with-param name="to"> Getai</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'romans_scipii'" />
            <xsl:with-param name="to"> Hayasdan</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'spain'" />
            <xsl:with-param name="to"> Iberia</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'greek_cities'" />
            <xsl:with-param name="to"> Koinon Hellenon</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'macedon'" />
            <xsl:with-param name="to"> Makedonia</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'parthia'" />
            <xsl:with-param name="to"> Pahlav</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'carthage'" />
            <xsl:with-param name="to"> Pontos</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'numidia'" />
            <xsl:with-param name="to"> Ptolemaioi</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'egypt'" />
            <xsl:with-param name="to"> Safot Softim biKarthadast</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'pontus'" />
            <xsl:with-param name="to"> Saka</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'armenia'" />
            <xsl:with-param name="to"> Sauromatae</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'seleucid'" />
            <xsl:with-param name="to"> Senatvs Popvlvsqve Romanvs</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'germans'" />
            <xsl:with-param name="to"> Swēbōzez</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'merc'" />
            <xsl:with-param name="to"> Mercenary</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="replace_mod">
            <xsl:with-param name="string" select="$ownership" />
            <xsl:with-param name="from" select="'slave'" />
            <xsl:with-param name="to"> Eleutheroi</xsl:with-param>
          </xsl:call-template>

          </div>
        </div>
      </div>

      <div class="separator"></div>


      <div class="Description">
        <img class="SmallMapImg" src="pics/Maps/Small/{$Type}.jpg" alt="N.A." title="Click for a bigger map!" onclick="showMap(event, '{$Type}');" />
        <p><xsl:value-of select='//description/short' /></p>
        <p>
          <xsl:call-template name="replace_and_keep">
            <xsl:with-param name="string" select="//description/long" />
            <xsl:with-param name="from" select="'&#xA;'" />
            <xsl:with-param name="to"><br /></xsl:with-param>
          </xsl:call-template>
        </p>
      </div>
    </div>

</xsl:template>
</xsl:stylesheet>